<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>sync</title>
</head>
<body>
  <script>
    function biaobai(delay,msg){
      return new Promise((resolve,reject)=>{
        setTimeout(()=>{
          resolve(msg);
        },delay)
      })
    }
    // 01 async装饰的函数返回的结果是一个promise
    // 02 async通常和await+promise一起
    // 03 Promise.all(数组) 等待数组中所有的promise都resolve后再执行完毕
    // 04 Promise.race(数组) 等待数组中的promise有一个最先执行再执行
    async function doit(){
      const r1 = await biaobai(2000,"咱加个微信吧");
      console.log(1)
      const r2 = await biaobai(5000," 我好中意你");
      console.log(2)
      const r3 = await biaobai(3000," 我们家祖坟风水不错,百年后一起呀!")
      console.log(3)
      console.log(Date.now())
      // const list = await Promise.all([biaobai(1000,"我新欢你"),biaobai(3000," .
      .
      
      
      ..Date"),biaobai(2000,"我更中意你的亿万家产")]);
      const list = await Promise.race([biaobai(1000,"我新欢你"),biaobai(3000," 但是我更喜欢你的才华"),biaobai(2000,"我更中意你的亿万家产")]);
      console.log(Date.now())
      console.log(4)
      return r1+r2+r3+list;
      // return r1+r2+r3+list.join(" ");
    }
   doit()
   .then(res=>{
      console.log(res)
    })
  </script>
</body>
</html>